//
//  WarrantyViewController.m
//  HondaPro_2
//
//  Created by ht on 13-9-3.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "WarrantyViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface WarrantyViewController ()

@end

@implementation WarrantyViewController

- (id)init
{
    self = [super init];
    if (self)
    {
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.view setFrame:CGRectMake(110, 160, 1024-110-110, 768-160-160)];
    
    [self loadCount];
    
    self.number = [[UILabel alloc]initWithFrame:CGRectMake(170, 120, 180, 35)];
    [self.number setBackgroundColor:[UIColor clearColor]];
    self.number.layer.borderColor = [[UIColor grayColor]CGColor];
    self.number.layer.borderWidth = 1;
    self.number.textColor = [UIColor grayColor];
    [self.number setTextAlignment:NSTextAlignmentCenter];
    self.number.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.number.text = self.numberStr;
    [self.view addSubview:self.number];
    
    self.work = [[UILabel alloc]initWithFrame:CGRectMake(170, 190, 400, 110)];
    [self.work setBackgroundColor:[UIColor clearColor]];
    self.work.layer.borderColor = [[UIColor grayColor]CGColor];
    self.work.layer.borderWidth = 1;
    self.work.textColor = [UIColor grayColor];
    [self.work setTextAlignment:NSTextAlignmentCenter];
    self.work.lineBreakMode = UILineBreakModeWordWrap;
    self.work.numberOfLines = 0;
    self.work.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.work.text = self.workStr;
    [self.view addSubview:self.work];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(170, 320, 190, 35)];
    [label setBackgroundColor:[UIColor whiteColor]];
    label.layer.borderColor = [[UIColor grayColor]CGColor];
    label.layer.borderWidth = 0.8;
    [self.view addSubview:label];
    self.stertTime = [[UIButton alloc]initWithFrame:CGRectMake(171, 321, 188, 33)];
    [self.stertTime setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
    [self.stertTime addTarget:self action:@selector(stertTime:) forControlEvents:UIControlEventTouchUpInside];
    [self.stertTime setTitle:self.stertTimeStr forState:UIControlStateNormal];
    self.stertTime.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:14];
    [self.stertTime setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.stertTime];
    
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(515, 320, 190, 35)];
    [label1 setBackgroundColor:[UIColor whiteColor]];
    label1.layer.borderColor = [[UIColor grayColor]CGColor];
    label1.layer.borderWidth = 0.8;
    [self.view addSubview:label1];
    self.endTime = [[UIButton alloc]initWithFrame:CGRectMake(516, 321, 188, 33)];
    [self.endTime setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
    [self.endTime addTarget:self action:@selector(endTime:) forControlEvents:UIControlEventTouchUpInside];
    [self.endTime setTitle:self.endTimeStr forState:UIControlStateNormal];
    self.endTime.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:14];
    [self.endTime setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.endTime];
    
    self.determineBtn = [[UIButton alloc]initWithFrame:CGRectMake(670, 390, 68, 30)];
    [self.determineBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self.determineBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.determineBtn setBackgroundImage:[UIImage imageNamed:@"ht05-1.png"] forState:UIControlStateNormal];
    self.determineBtn.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.determineBtn addTarget:self action:@selector(determineBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.determineBtn];
}
-(void)determineBtn:(id)sender
{
    NSMutableArray *strArray = [[NSMutableArray alloc]initWithCapacity:10];
    NSString *str1 = self.stertTime.titleLabel.text;
    NSString *str2 = self.endTime.titleLabel.text;
    [strArray addObject:str1];
    [strArray addObject:str2];
    NSNotification *notification = [NSNotification notificationWithName:@"modifyTime" object:strArray];
    [[NSNotificationCenter defaultCenter]postNotification:notification];
}
#pragma mark - 实际开始时间的回调
-(void)stertTime:(id)sender
{
    if (self.popController.popoverVisible)
    {
        [self.popController dismissPopoverAnimated:YES];
        return;
    }
    self.popoverCtl = [[UIViewController alloc] init];
    self.popoverCtl.view.backgroundColor = [UIColor yellowColor];
    self.popController = [[UIPopoverController alloc] initWithContentViewController:self.popoverCtl];
    self.popController.popoverContentSize = CGSizeMake(310.0f, 160.0f);
    [self.popController presentPopoverFromRect:CGRectMake(0, 0, 215, 40) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    self.yuyueDate = self.datePicker.date;
    self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 310, 160)];
    self.datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:NSLocalizedString(@"Chinese", @"")];
    self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    [self.datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    [self.popoverCtl.view addSubview:self.datePicker];
}
-(void)dateChanged:(id)sender
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    self.yuyueDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:self.datePicker.date]];
    [self.stertTime setTitle:[NSString stringWithFormat:@"%@",self.yuyueDate] forState:UIControlStateNormal];
}
#pragma mark - 实际结束时间的回调
-(void)endTime:(id)sender
{
    if (self.popController.popoverVisible)
    {
        [self.popController dismissPopoverAnimated:YES];
        return;
    }
    self.popoverCtl = [[UIViewController alloc] init];
    self.popoverCtl.view.backgroundColor = [UIColor yellowColor];
    self.popController = [[UIPopoverController alloc] initWithContentViewController:self.popoverCtl];
    self.popController.popoverContentSize = CGSizeMake(310.0f, 160.0f);
    [self.popController presentPopoverFromRect:CGRectMake(0, 0, 215, 40) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    self.yuyueDate = self.datePicker.date;
    self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 310, 160)];
    self.datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:NSLocalizedString(@"Chinese", @"")];
    self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    [self.datePicker addTarget:self action:@selector(dateChanged1:) forControlEvents:UIControlEventValueChanged];
    [self.popoverCtl.view addSubview:self.datePicker];
}
-(void)dateChanged1:(id)sender
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    self.yuyueDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:self.datePicker.date]];
    [self.endTime setTitle:[NSString stringWithFormat:@"%@",self.yuyueDate] forState:UIControlStateNormal];
}
-(void)loadCount
{
    UIImageView *imageline= [[UIImageView alloc]initWithFrame:CGRectMake(10, 80, 780, 2)];
    imageline.image = [UIImage imageNamed:@"红色分割线.png"];
    [self.view addSubview:imageline];
    
    UILabel *titile = [[UILabel alloc]initWithFrame:CGRectMake(330, 20, 100, 40)];
    titile.text = @"保修实绩";
    titile.backgroundColor = [UIColor clearColor];
    titile.textColor = [UIColor grayColor];
    titile.font = [UIFont fontWithName:@"ArialMT" size:24];
    [self.view addSubview:titile];
    
    UILabel *number = [[UILabel alloc]initWithFrame:CGRectMake(90, 120, 80, 40)];
    number.text = @"修理单号:";
    number.backgroundColor = [UIColor clearColor];
    number.textColor = [UIColor grayColor];
    number.font = [UIFont fontWithName:@"ArialMT" size:17];
    [self.view addSubview:number];
    
    UILabel *work = [[UILabel alloc]initWithFrame:CGRectMake(90, 190, 80, 40)];
    work.text = @"作业内容:";
    work.backgroundColor = [UIColor clearColor];
    work.textColor = [UIColor grayColor];
    work.font = [UIFont fontWithName:@"ArialMT" size:17];
    [self.view addSubview:work];
    
    UILabel *startTime = [[UILabel alloc]initWithFrame:CGRectMake(55, 320, 120, 40)];
    startTime.text = @"实际开始时间:";
    startTime.backgroundColor = [UIColor clearColor];
    startTime.textColor = [UIColor grayColor];
    startTime.font = [UIFont fontWithName:@"ArialMT" size:17];
    [self.view addSubview:startTime];
    
    UILabel *endTime = [[UILabel alloc]initWithFrame:CGRectMake(390, 320, 120, 40)];
    endTime.text = @"实际结束时间:";
    endTime.backgroundColor = [UIColor clearColor];
    endTime.textColor = [UIColor grayColor];
    endTime.font = [UIFont fontWithName:@"ArialMT" size:17];
    [self.view addSubview:endTime];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
